package com.talon.pld_player;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.pili.pldroid.player.AVOptions;
import com.pili.pldroid.player.PLOnCompletionListener;
import com.pili.pldroid.player.PLOnErrorListener;
import com.pili.pldroid.player.PLOnInfoListener;
import com.pili.pldroid.player.PLOnPreparedListener;
import com.pili.pldroid.player.PLOnVideoSizeChangedListener;
import com.pili.pldroid.player.widget.PLVideoView;
import com.talon.lib_base.ConfigApi;

public class PlaPlayerActivity extends AppCompatActivity implements PLOnPreparedListener,
        PLOnInfoListener,
        PLOnCompletionListener,
        PLOnVideoSizeChangedListener,
        PLOnErrorListener {
    private PLVideoView plVideoView;

    private String TAG = "七牛播放器~~";
    private long time = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_plactivity);
        plVideoView = findViewById(R.id.plview);
        String url = ConfigApi.videoUrl;
        plVideoView.setVideoPath(url);
        AVOptions options = new AVOptions();
        options.setInteger(AVOptions.KEY_MEDIACODEC, AVOptions.MEDIA_CODEC_AUTO);
        plVideoView.setAVOptions(options);
        plVideoView.setDisplayAspectRatio(PLVideoView.ASPECT_RATIO_PAVED_PARENT);
        plVideoView.setOnPreparedListener(this);
        plVideoView.setOnInfoListener(this);
        plVideoView.setOnCompletionListener(this);
        plVideoView.setOnVideoSizeChangedListener(this);
        plVideoView.setOnErrorListener(this);
        time = System.currentTimeMillis();
        plVideoView.start();
        findViewById(R.id.res).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                plVideoView.stop();
                plVideoView.setVideoPath(ConfigApi.videoUrl2);
                time = System.currentTimeMillis();
                plVideoView.start();

            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onStop() {
        super.onStop();
        plVideoView.stop();
        plVideoView.stopPlayback();
    }


    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {
        super.onPointerCaptureChanged(hasCapture);
    }

    @Override
    public void onCompletion() {

    }

    @Override
    public boolean onError(int i, Object o) {
        return false;
    }

    @Override
    public void onInfo(int i, int i1, Object o) {
        if (i == PLOnInfoListener.MEDIA_INFO_VIDEO_RENDERING_START) {
            float result = System.currentTimeMillis() - time;
            Log.i("xiaote", TAG + "onPrepared time :" + result);
        }
    }

    @Override
    public void onVideoSizeChanged(int i, int i1) {

    }

    @Override
    public void onPrepared(int i) {

    }
}